<% layout('/layout/default.html', {title: '用户管理', libs: ['dataGrid','icheck']}){ %>
<div class="main-content">
	<div class="card-header">
		<i class="fa icon-user"></i> 用户管理
		<div class="header-tools float-right">
			<a href="#" class="btn btn-sm btn-secondary" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
			<a href="#" class="btn btn-sm btn-secondary"  id="btnRefreshTree" title="刷新"><i class="fa fa-refresh"></i> 刷新</a>
			<% if(hasPermi('sys:user:edit')){ %>
			<a href="/sys/user/form" class="btn btn-sm btn-secondary btnTool" title="新增用户"><i class="fa fa-plus"></i> 新增</a>
			<div class="btn-group">
				<a href="javascript:" class="btn btn-sm btn-secondary dropdown-toggle" data-toggle="dropdown">
					<i class="fa fa-navicon"></i> <span class="caret"></span>
				</a>
				<ul class="dropdown-menu">
					<li><a href="${ctx}/sys/user/export" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a></li>
					<li><a href="javascript:" id="btnImport"><i class="glyphicon glyphicon-import"></i> 导入</a></li>
				</ul>
			</div>
			<% } %>
		</div>
	</div>
	<div class="container-fluid">
		<form id="searchForm" action="${ctx}/sys/user/listData" class="form-inline d-none" >
			<div class="form-group">
				<label class="control-label">登录名：</label>
				<div class="control-inline">
					<#form:input path="loginName" maxlength="100" class="form-control width-90"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">邮箱：</label>
				<div class="control-inline">
					<#form:input path="email" maxlength="300" class="form-control width-90"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">手机：</label>
				<div class="control-inline">
					<#form:input path="mobile" maxlength="100" class="form-control width-90"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">电话：</label>
				<div class="control-inline">
					<#form:input path="phone" maxlength="100" class="form-control width-90"/>
				</div>
			</div>
			<div class="form-row"></div>
			<div class="form-group">
				<label class="control-label">用户名：</label>
				<div class="control-inline">
					<#form:input path="name" maxlength="100" class="form-control width-90"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">状态：</label>
				<div class="control-inline width-90">
					<#form:select path="loginFlag" name="label" data="getDictList:sys_user_status"  blankOption="true" class="form-control" isSubTag="false"/>
				</div>
			</div>
			<div class="form-group">
				<button type="submit" class="btn btn-primary ">查询</button>
				<button id="reset" type="reset" class="btn btn-secondary ">重置</button>
			</div>
		</form>
		<table id="btGrid"></table>
	</div>
</div>
<script type="text/javascript">
    $('#reset').click(function(){
        $('#loginFlag').val(null).trigger("change");
    });

    $('#btnImport').click(function(){
		js.layer.open({
			type: 1,
			area: ['400px'],
			title: '导入用户数据',
			resize: false,
			scrollbar: true,
			content: js.formatHtml('importTpl'),
			btn: ['<i class="fa fa-check"></i> 导入',
				'<i class="fa fa-remove"></i> 取消'],
            yes: function(index, layero){
				console.log(layero.find('#file').val());
				var form = {
					inputForm: layero.find('#inputForm'),
					file: layero.find('#file').val()
				};
			    if (form.file == '' || (!js.endWith(form.file, '.xls') && !js.endWith(form.file, '.xlsx'))){
			    	js.showMessage("文件不正确，请选择后缀为 “xls”或“xlsx”的文件。", null, 'warning');
			        return false;
			    }
				js.ajaxSubmitForm(form.inputForm, function(data){
					console.log(data);
					js.layer.closeAll();
					js.showMessage(data.message);
					page();
				});
				return true;
			},
            btn2: function(index, layero){
            }
		});
	});
</script>
<script id="importTpl" type="text">//<!--
<form id="inputForm" action="${ctx}/sys/user/import" method="post" enctype="multipart/form-data"
	class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
	<div class="row">
		<div class="col-xs-12 col-xs-offset-1">
			<input type="file" id="file" name="file" class="form-file"/>
			<div class="mt10 pt5">
				<a href="${ctx}/sys/user/import/template" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
			</div>
			<font color="red" class="pull-left mt10">
				提示：仅允许导入“xls”或“xlsx”格式文件！
			</font>
		</div>
	</div>
</form>
//--></script>
<% } %>
<script>
// 初始化DataGrid对象
$('#btGrid').BTGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{title:'登录名', field:'loginName', width:100, align:"center", sortable:true},
		{title:'用户名', field:'name', width:100, align:"center", sortable:true},
		{title:'归属公司', field:'company.name', width:120, align:"center"},
		{title:'归属机构', field:'office.name', width:120, align:"center"},
		{title:'手机号码', field:'mobile', width:100, align:"center"},
		{title:'办公电话', field:'phone', width:100, align:"center"},
		{title:'状态', field:'loginFlag', width:120, align:"center", formatter: function(val, row, index){
			return js.transDictLabel(${@DictUtils.getDictListJson('sys_user_status')}, val, '未知');
		}},
		{title:'操作', field:'id', width:200, align:"center", formatter: function(val, row, index){
			var actions = [];
			var icon = row.loginFlag==1?'title="停用用户" data-confirm="确认要停用该用户吗?"><i class="fa fa-ban':'title="启用用户" data-confirm="确认要启该用户吗?"><i class="fa fa-check-square';
			<% if(hasPermi('sys:user:edit')){ %>
				actions.push('<a href="/sys/user/form?id='+row.id+'&op=edit" class="btn btn-sm btn-success  btnList" title="编辑用户"><i class="fa fa-pencil"></i></a>&nbsp&nbsp');
				actions.push('<a href="${ctx}/sys/user/changeStatus?id='+row.id+'&loginFlag='+row.loginFlag+'" class="btn btn-sm btn-primary btnList"'+icon+'"></i></a>&nbsp&nbsp');
				actions.push('<a href="${ctx}/sys/user/resetPass?id='+row.id+'&loginName='+row.loginName+'" class="btn btn-sm btn-primary btnList" title="重置密码" data-confirm="确认要重置为默认密码吗?"><i class="fa fa-reply-all"></i></a>&nbsp&nbsp');
				actions.push('<a href="${ctx}/sys/user/delete?id='+row.id+'" class="btn btn-sm btn-danger btnList" title="删除用户" data-confirm="确认要删除该用户吗?"><i class="fa fa-trash-o"></i></a>');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
